﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MaoCaiJun.DataBase.Configuration.DbsAnalysis
{
    //[System.Xml.Serialization.XmlType("")]
    [System.Serializable]
    [System.Xml.Serialization.XmlRoot(ElementName = "MaoCaiJunDataBase-mapping",Namespace="http://www.caijun.net")]
    public class MaoCaiJunDataBaseMapping
    {
        public MaoCaiJunDataBaseMapping()
        {
        }
        public MaoCaiJunDataBaseMapping(string path)
            : this()
        {
            OpenDBS(path);
        }
        public MaoCaiJunDataBaseMapping(System.IO.Stream inStream)
            : this()
        {
            OpenDBS(inStream);
        }
        public MaoCaiJunDataBaseMapping(System.IO.TextReader txtReader)
            : this()
        {
            OpenDBS(txtReader);
        }

        public MaoCaiJunDataBaseMapping(System.Xml.XmlReader reader)
            : this()
        {
            OpenDBS(reader);
        }

 
        

        
        //[System.Xml.Serialization.XmlType()]

        //[System.Xml.Serialization.XmlArray("namespace")]
        //[System.Xml.Serialization.XmlArrayItem("namespace")]

        private NamespaceList _namespace = new NamespaceList();
        public NamespaceList Namespace { get { return _namespace; } set { _namespace = value; } }
        public void OpenDBS(string path) {
            MaoCaiJunDataBaseMapping map = SerializationHelper.DeserializeFromXmlFile<MaoCaiJunDataBaseMapping>(path);
          this.Namespace=  map.Namespace;
        }
        private void OpenDBS(System.IO.Stream inStream)
        {
            using (System.IO.StreamReader sr = new System.IO.StreamReader(inStream))
            {
                MaoCaiJunDataBaseMapping map = SerializationHelper.DeserializeFromXml<MaoCaiJunDataBaseMapping>(sr.ReadToEnd());
                this.Namespace = map.Namespace;
            }
        }

        private void OpenDBS(System.IO.TextReader txtReader)
        {
            MaoCaiJunDataBaseMapping map = SerializationHelper.DeserializeFromXml<MaoCaiJunDataBaseMapping>(txtReader.ReadToEnd());
                this.Namespace = map.Namespace;
        }
        private void OpenDBS(System.Xml.XmlReader reader)
        {
            MaoCaiJunDataBaseMapping map = SerializationHelper.DeserializeFromXml<MaoCaiJunDataBaseMapping>(reader.ReadOuterXml());
            this.Namespace = map.Namespace;

        }
        public bool SeveDBS(string path)
        {
           return  SerializationHelper.SerializeToXmlFile(this,path);
        }

    }
}
